<template>
	<view class="web-box">
		<!-- <HeadCustom :isAppBtn="false" :isHome="false"></HeadCustom> -->
		<web-view v-if="pageUrl" :src="pageUrl" @message="getH5Message"></web-view>
	</view>
</template>

<script>
import {base64encode, utf8to16} from '@/static/js/Base64.js'
export default {
	data() {
		return {
			pageUrl: '', // 'https://dwz.cn/7EdmGvAR'
			isHead: false
		};
	},
	onLoad(option) {
		console.log(option)
		this.getInit(option)
	},
	methods: {
		getInit(option){
			const url = decodeURIComponent(decodeURI(option.url))
			// 打开内部网站添加token，小程序web-view自带头部。隐藏头部
			const { bw_params } = getApp().getBWData(['bw_params']);
			const token = bw_params.access_token
			let newUrl = url
			if(url.includes('benwunet.com')){
				let param =  ''
				if(token){ param =  base64encode(`token=${token}`) }
				if(url.includes('?')){
					newUrl = `${url}&isHead=1`
				}else{
					newUrl = `${url}?isHead=1`
				}
				if(token){
					newUrl = `${newUrl}&benwu=${param}`
				}
			}
			console.log('新的URL：',newUrl)
			this.pageUrl = newUrl;
		},
		getH5Message(e){
			console.log('来自webview的消息', e)
		}
	}
};
</script>

<style lang="scss" scoped>
.web-box {
	min-height: 100vh;
}
</style>
